﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ipaidabribe.Code
{
    public class Thongke
    {
        public double ThongkeTq()
        {
            double rs = 0;
            try
            {
                var helper = new DataHelper();
                var re =
                    helper.ExecuteQuery<double>(
                        "SELECT SUM(convert(float, AmountPaid)) as total FROM [dbo].[Bribe] WHERE ISNUMERIC(AmountPaid) <> 0 and [Enable] = 1")
                        .FirstOrDefault();
                rs = re;
            }
            catch (Exception)
            {
                return rs;
                //throw;
            }
            return rs;
        }

        public List<ThongkeTpItem>ThongkeTop5Tp()
        {
            var lst = new List<ThongkeTpItem>();
            try
            {
                var helper = new DataHelper();
                var re =
                    helper.ExecuteQuery<ThongkeTpItem>(
                        "SELECT top 10 City, SUM( convert(float, AmountPaid)) as Total, Count(*) as CountTransaction FROM [dbo].[Bribe] WHERE ISNUMERIC(AmountPaid) <> 0 and [Enable] = 1 group by City order by SUM( convert(float, AmountPaid)) desc")
                        .ToList();
                lst = re;
            }
            catch (Exception)
            {
                return lst;
                //throw;
            }
            return lst;
        }
    }

    public class ThongkeTpItem
    {
        public string City { get; set; }
        public double Total { get; set; }
        public int CountTransaction { get; set; }
    }
    public class ThongkeNganhnghe
    {
        public string Department { get; set; }
        public double Total { get; set; }
        public int CountTransaction { get; set; }
    }
}